package com.wavehi.dao.impl;

import com.wavehi.dao.BaseDao;
import com.wavehi.pojo.Employee;
import com.wavehi.dao.IEmployeeDAO;

import java.util.List;

/**
 * @Author WaveHi
 * @Date 3/9/2021 下午 8:58
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description
 */
public class EmployeeDAOImpl extends BaseDao implements IEmployeeDAO {
    @Override
    public void add(Employee em) {
        String sql = "insert into t_employee(e_name, e_phone) values(?,?)";
        update(sql, em.getName(), em.getPhone());
    }

    @Override
    public void delete(Long id) {
        String sql = "delete from t_employee where e_id=?";
        update(sql, id);
    }

    @Override
    public void update(Employee em) {
        String sql = "update t_employee set e_name=?, e_phone=? where e_id=?";
        update(sql, em.getName(), em.getPhone(), em.getId());
    }

    @Override
    public Employee select(String name) {
        String sql = "select e_id id, e_name name, e_phone phone from t_employee where e_name=?";
        return selectForOne(Employee.class, sql, name);
    }

    @Override
    public List<Employee> list() {
        String sql = "select e_id id, e_name name, e_phone phone from t_employee";
        return selectForList(Employee.class, sql);
    }
}
